const textEle = document.getElementById('text')
const speedEle = document.getElementById('speed')
let text = 'Before the morning sun when life was lonely'
let speed = 500 / speedEle.value
let idx = 1

writeText()

function writeText(){
    textEle.innerText = text.slice(0, idx)
    idx++
    if(idx >= text.length) idx = 1
    setTimeout(writeText, speed)
}
speedEle.addEventListener('input', (e)=> speed = 500/e.target.value)